package com.xl.sharedModel;

import lombok.extern.slf4j.Slf4j;

/**
 * JdkVersion: 1.8
 * Author: lei·xie
 * Created: 2024/8/7 0007 10:44
 * Description: 共享模型 synchronized
 */
@Slf4j(topic = "c.Test2")
public class Test02 {

    static int count = 0;
    static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                synchronized(lock) {
                    count++;
                }
            }
        },"t1");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                synchronized(lock) {
                    count--;
                }
            }
        },"t2");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        log.debug("count:{}", count);
    }
}
